package com.ai.emall.utils.exception;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ai.emall.utils.util.GnExceptionCodeUtil;


public class BusinessException extends GenericException {

    private static final long serialVersionUID = 1L;

    private static Log log = LogFactory.getLog(BusinessException.class);

    public BusinessException(String errorCode) {
        super(GnExceptionCodeUtil.convertError(errorCode));
        this.errorCode = errorCode;
        this.errorMessage = GnExceptionCodeUtil.convertError(errorCode);
        this.writeBusinessException();
    }

    public BusinessException(String errorCode, String[] keyInfos) {
        super(GnExceptionCodeUtil.convertError(errorCode, keyInfos));
        this.errorCode = errorCode;
        this.errorMessage = GnExceptionCodeUtil.convertError(errorCode, keyInfos);
        this.writeBusinessException();
    }

    public BusinessException(String errorCode, String keyInfo) {
        super(GnExceptionCodeUtil.convertError(errorCode, keyInfo));
        this.errorCode = errorCode;
        this.errorMessage = GnExceptionCodeUtil.convertError(errorCode, keyInfo);
        this.writeBusinessException();
    }

    public BusinessException(String errorCode, String errorMessage, boolean notransfer) {
        super(notransfer ? errorMessage : GnExceptionCodeUtil.convertError(errorCode, errorMessage));
        this.errorCode = errorCode;
        this.errorMessage = notransfer ? errorMessage : GnExceptionCodeUtil.convertError(errorCode,
                errorMessage);
        this.writeBusinessException();
    }

    private void writeBusinessException() {
        log.error("业务异常编码：" + this.getErrorCode());
        log.error("业务异常信息：" + this.getErrorMessage());
    }
}
